package com.lbb.utils

import android.app.Activity
import java.util.*

object ActivityCollectorUtil {
    private val activityStack: Stack<Activity> = Stack()

    /**
     * 拿到最后添加的Activity
     */
    fun getLastActivity(): Activity? {
        return activityStack.lastElement()
    }

    /**
     * 拿到第一个添加的Activity
     */
    fun getFirstActivity(): Activity? {
        return activityStack.firstElement()
    }

    /**
     * 添加Activity到堆栈
     */
    fun addActivity(activity: Activity?) {
        activityStack.add(activity)
    }

    /**
     * 结束指定的Activity
     */
    fun removeActivity(activity: Activity?) {
        activityStack.remove(activity)
    }


    /**
     * 结束所有Activity
     */
    fun removeAllActivity() {
        for (activity in activityStack) {
            removeActivity(activity)
        }
    }

}